package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import utils.MyUtil;

public class HJ29_最多提取子串数目 {
  public static void main(String[] args) throws FileNotFoundException {
    // 方法一：暴力解法
    //    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/29.txt"));
    //    MyUtil.START();
    //    String s1 = in.nextLine();
    //    String s2 = in.nextLine();
    //    StringBuilder sb1 = new StringBuilder(s1);
    //    int res = 0;
    //    while (true) {
    //      int before = -1;
    //      for (int i = 0; i < s2.length(); i++) {
    //        char now = s2.charAt(i);
    //        int index = sb1.indexOf(now + "");
    //        if (index != -1) {
    //          if (before != -1 && before > index) {
    //            System.out.println(res);
    //            return;
    //          }
    //          sb1.replace(index, index + 1, "");
    //          before = index;
    //        } else {
    //          System.out.println(res);
    //          MyUtil.END();
    //          return;
    //        }
    //      }
    //      res++;
    //    }

    // 方法二：双指针
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/29.txt"));
    MyUtil.START();
    char[] s1Char = in.nextLine().toCharArray();
    char[] s2Char = in.nextLine().toCharArray();
    int index1 = 0;
    int index2 = 0;
    int res2 = 0;
    while (index1 < s1Char.length) {
      if (s1Char[index1] == s2Char[index2]) {
        s1Char[index1] = ' ';
        index1++;
        index2++;
      } else {
        index1++;
      }
      if (index2 == s2Char.length) {
        res2++;
        index1 = 0;
        index2 = 0;
      }
    }
    System.out.println(res2);
    MyUtil.END();
  }
}
